from src.core import *
from src.utils import *
import os
import numpy as np
from libsvm.tools.grid import *

feature_folder = r'H:\wangjianlian\project\Python\image-pretreatment\resources\features'
method = 'GLCM'
trained_feature_folder = os.path.join(feature_folder, method, "train")
optimized_feature_folder = os.path.join(feature_folder, method, "optimize")


# # 读取训练文件夹所有的txt文件
# txt_paths = []
# data = Data()
# data.find_inside_file(txt_paths, trained_feature_folder)
#
# # 将特征集合在一起
# svm = SVM()
# all_x = []
# all_y = []
# for txt_path in txt_paths:
#     y, x = svm.read_feature(txt_path)  # 读入训练文件
#     # 将几个文件的特征合在一起
#     all_x += x
#     all_y += y
# all_y = np.array(all_y)
# all_x = trans_features2numpy(all_x)
#
# ft = Feature()
# ft.save_integrated_txt(all_x, all_y, os.path.join(optimized_feature_folder, "train_all.txt"))


best_rate, best_param = find_parameters(os.path.join(optimized_feature_folder, "train_all.txt"))
param_list = list(best_param.values())
options = '-c ' + str(param_list[0]) + ' ' + '-g ' + str(param_list[1]) + ' ' + '-b 0'

a = 1